{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Variables are manipulated via the tf.Variable class.\n",
    "# A tf.Variable represents a tensor whose value can be changed by running ops on it.\n",
    "# Specific ops allow you to read and modify the values of this tensor.\n",
    "\n",
    "## Creaging a Variable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor: <tf.Variable 'my/Variable:0' shape=() dtype=int32, numpy=1>\n",
      "value: 1\n"
     ]
    }
   ],
   "source": [
    "with tf.name_scope(\"my\"):\n",
    "    variable = tf.Variable(1)\n",
    "print(\"tensor:\", variable)\n",
    "print(\"value:\", variable.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Using Variables\n",
    "\n",
    "# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "value: 2\n"
     ]
    }
   ],
   "source": [
    "variable = variable + 1\n",
    "print(\"value:\", variable.numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Using Variables\n",
    "\n",
    "# To use the value of a tf.Variable in a TensorFlow graph, simply treat it like a normal tf.Tensor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "value: 3\n"
     ]
    }
   ],
   "source": [
    "variable = tf.Variable(2)\n",
    "variable.assign_add(1)\n",
    "print(\"value:\", variable.numpy())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
